/*
 * 
 * 
 * 
 */
package com.hboxs.asl.controller.admin;

import com.hboxs.asl.Template;
import com.hboxs.asl.service.StaticService;
import com.hboxs.asl.service.TemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;

/**
 * Controller - Sitemap
 */
@Controller("adminSitemapController")
@RequestMapping("/asl-admin/sitemap")
public class SitemapController extends BaseController {

    @Resource(name = "templateServiceImpl")
    private TemplateService templateService;
    @Resource(name = "staticServiceImpl")
    private StaticService staticService;

    /**
     * 生成Sitemap
     */
    @RequestMapping(value = "/build", method = RequestMethod.GET)
    public String build(ModelMap model) {
        Template sitemapIndexTemplate = templateService.get("sitemapIndex");
        model.addAttribute("sitemapIndexPath", sitemapIndexTemplate.getStaticPath());
        return "/admin/sitemap/build";
    }

    /**
     * 生成Sitemap
     */
    @RequestMapping(value = "/build", method = RequestMethod.POST)
    public String build(RedirectAttributes redirectAttributes) {
        staticService.buildSitemap();
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:build.htm";
    }

}